<?php
namespace app\admin\controller;

use app\common\component\user_wallet_gold\UserWalletGoldModel;

class UserWalletGold extends ControllerBase {
	public function _initialize() {
		$this -> checkLogin();
	}

	public function index() {
		$userWalletGolds = UserWalletGoldModel::alias('u_w_g')
			-> join('league_user u', 'u_w_g.user_id = u.user_id')
			-> field(
				'u_w_g.*, ' .
				'u.username, u.realname, u.phone, u.bank_code'
			)
			->order('u_w_g.status ASC') -> paginate(10);
		
		$this -> view -> assign('userWalletGolds', $userWalletGolds);

		return $this -> view -> fetch();
	}

	public function checkTopUp() {
		$this -> doUpdate(['status' => 3], $this -> request -> get('user_wallet_gold_id'));
	}

	public function checkWithdraw() {
		$this -> doUpdate(['status' => 9], $this -> request -> get('user_wallet_gold_id'));
	}
	
	private function doUpdate($data, $user_wallet_gold_id) {
    	if(UserWalletGoldModel::where('user_wallet_gold_id', $user_wallet_gold_id) -> update($data)) {
			echo '<meta charset="utf-8"><script>alert("审核成功!");window.location.href="/shuashuale/wallet/gold";</script>';exit;
		}
		echo '<meta charset="utf-8"><script>alert("审核失败!");window.location.href="/shuashuale/wallet/gold";</script>';exit;
	}
}